/* 
 * Copyright [2018] [Alex/libo(liboms@hotmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.apidoc.scanner;

import java.util.List;

import com.hyts.apidoc.base.AbstractScanner;
import com.hyts.apidoc.bean.ScanBaseObject;
import com.hyts.apidoc.bean.ScanExtObject;
import com.hyts.apidoc.bean.ScanResultObject;
import com.hyts.apidoc.scanner.help.ClassHelper;
import com.hyts.apidoc.scanner.help.ScanHelper;

/** 
 * @title SourceScanner.java  
 * @package com.hyts.apidoc.scanner  
 * @description source代码相关的扫描机制，专属扫描source源码内,匹配此包结构的相关类,
 * 				默认扫描所有相关的机械性扫描类，可以控制扫描范围，扫描机制
 * 				递归，且可以根据系统提供相关的注解、继承类进行深层限制和控
 * 				制范围    
 * @see TODO
 * @author libo/Alex
 * @email liboms@hotmail.com/liboware@163.com  
 * @date 2018年4月18日 
 * @version V1.0 
 */
public class SourceScanner extends AbstractScanner{
	
	
	/**  
	 * <p>是否递归</p> 
	 * @fieldName isRecursive
	 * @fieldType boolean
	 */ 
	private boolean isRecursive;

	/**  
	 * @constructor：SourceScanner  
	 * @param isRecursive  
	 */ 
	public SourceScanner(boolean isRecursive) {
		super();
		this.isRecursive = isRecursive;
	}

	/**  
	 * @constructor：SourceScanner    
	 */ 
	public SourceScanner() {
		super();
		this.isRecursive = true;
	}
	
	/* (非 Javadoc)
	 * <b>TODO(方法功能的描述)-  scan </b>
	 * <p>TODO(这里用一句话描述这个方法的作用)</p>
	 * @param scanObject
	 * @return
	 * @see com.hyts.apidoc.base.AbstractScanner#scan(com.hyts.apidoc.bean.ScanBaseObject)  
	 * @exception
	 */ 
	@Override
	public ScanResultObject scan(ScanBaseObject scanObject) {
		//判断属于那种解析操作，系统自动识别-进行切换扫描复杂度
		ScanResultObject result = new ScanResultObject();
		if(scanObject instanceof ScanBaseObject) {
			List<String> resultFileList= isRecursive?
						new ScanHelper().scanRecursive(scanObject):new ScanHelper().scanNonRecursive(scanObject);
			for(String filePath:resultFileList)	{
				String filePath2 = ClassHelper.filePathToUserPath(filePath, scanObject.packages);
				result.addResultFile(filePath2);
				Class<?> className = ClassHelper.filePathToClass(filePath, scanObject.packages);
				result.addResultClass(className);
			}
		}else if(scanObject instanceof ScanExtObject){
			ScanExtObject newScanObject = (ScanExtObject)scanObject;
		}
		return result;
	}
	
	
	
	
}
